//
//  JCTagCell.m
//  JCTagListView
//
//  Created by 李京城 on 15/7/3.
//  Copyright (c) 2015年 李京城. All rights reserved.
//

#import "JCTagCell.h"

@interface JCTagCell ()

@property (nonatomic, strong) UIButton *titleLabel;

@end

@implementation JCTagCell

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.layer.masksToBounds = YES;
//        self.layer.borderWidth = 1.0f;
//        self.layer.borderColor = [UIColor darkGrayColor].CGColor;
        self.backgroundColor = [UIColor colorWithRed:236/255.0 green:241/255.0 blue:248/255.0 alpha:1];
        ;
        
        self.titleLabel = [[UIButton alloc] initWithFrame:self.bounds];
        [self.titleLabel setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [self.titleLabel setBackgroundImage:[self imageWithColor:[UIColor colorWithRed:236/255.0 green:241/255.0 blue:248/255.0 alpha:1]] forState:UIControlStateNormal];
        self.titleLabel.titleLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.titleLabel];
    }
    
    return self;
}

- (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.titleLabel.frame = self.bounds;
    self.layer.cornerRadius = CGRectGetHeight(self.bounds)/2;

}

- (void)prepareForReuse
{
    [super prepareForReuse];
    
    [self.titleLabel setTitle:@"" forState:UIControlStateNormal];
}

- (void)setTitle:(NSString *)title
{
    _title = title;
    [self.titleLabel setTitle:title forState:UIControlStateNormal];

}

@end
